<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class TaskRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(Request $request)
    {
        switch ($this->method()) {
            case 'POST':
                $rules =  [
                    'name' => 'required|string|min:2|max:20',
                    'carry_user_id' => 'required',
                    'carry_user_id' => [
                        Rule::exists('users','id')->whereNull('deleted_at')
                    ],
                    'ids' => 'array',
                    'ids.*' => 'exists:mysql_branch.fs_user,id',
                    'start_time'=>'required|date',
                    'end_time'=>'required|date'
                ];
                break;
            case 'PATCH':
                $rules =  [
                    'name' => 'nullable|string|min:2|max:20',
                    'carry_user_id' => 'nullable',
                    'carry_user_id' => [
                        Rule::exists('users','id')->whereNull('deleted_at')
                    ],
                    'ids' => 'array|required',
                    'ids.*' => 'exists:mysql_branch.fs_user,id',
                    'start_time'=>'required|date',
                    'end_time'=>'required|date'
                ];
                break;
        }

        return $rules;
    }

    public function attributes()
    {
        return [
            'ids.*'=>'会员'
        ];
    }
}
